package vip.xiaonuo.modular.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import vip.xiaonuo.modular.sso.NjuSsoInterceptor;
import vip.xiaonuo.sys.modular.auth.service.AuthService;
import vip.xiaonuo.sys.modular.syscollege.service.SysCollegeService;
import vip.xiaonuo.sys.modular.user.service.SysUserService;

@Configuration
public class NjuWebMvcConfig implements WebMvcConfigurer {

    private final SysUserService userService;
    private final AuthService authService;
    private final SysCollegeService sysCollegeService;

    public NjuWebMvcConfig(SysUserService userService, AuthService authService, SysCollegeService sysCollegeService) {
        this.userService = userService;
        this.authService = authService;
        this.sysCollegeService = sysCollegeService;
    }

    @Bean("njuSsoInterceptor")
    public NjuSsoInterceptor njuSsoInterceptor() {
        return new NjuSsoInterceptor(userService, authService, sysCollegeService);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(njuSsoInterceptor());
    }
}
